package com.crime.crimemonitorclient;

import java.util.Calendar;
import java.util.GregorianCalendar;

import com.androidplot.xy.XYSeries;
import com.crimemonitor.library.CrimeTimeSeriesObservation;

public class CrimesCommittedTimeSeries implements XYSeries
{

	private final String title;
	private final CrimeTimeSeriesObservation[] observations;
	
	public CrimesCommittedTimeSeries(String title, CrimeTimeSeriesObservation[] observations)
	{
		if(observations == null)
			throw new IllegalArgumentException("The observations parameter cannot be null.");
		
		this.title = title;
		this.observations = observations;
	}
	
	@Override
	public String getTitle() {
		return this.title;
	}

	@Override
	public int size() {
		return this.observations.length;
	}

	@Override
	public Number getX(int index) {
		CrimeTimeSeriesObservation observation = this.observations[index];
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.YEAR, observation.getObsYear());
		calendar.set(Calendar.MONTH, observation.getObsMonth());
		
		return calendar.getTimeInMillis();
	}

	@Override
	public Number getY(int index) {
		CrimeTimeSeriesObservation observation = this.observations[index];
		return observation.getObsValue();
	}

}
